package com.basker.pisces.concurrent.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.basker.pisces.concurrent.lock.ILockManager;
import com.basker.pisces.concurrent.lock.LocalLockManager;
import com.basker.pisces.config.Constants;

@Configuration
public class LocalLockManagerConfiguration {

    public static final String DEFAULT_LOCK_MANAGER = Constants.DEFAULT_LOCK_MANAGER;

    /**
     * 如果不存在其他{@value #DEFAULT_LOCK_MANAGER}的ILockManager,则默认缓存管理器为{@link LocalLockManager}
     *
     * @return
     */
    @Bean(name = DEFAULT_LOCK_MANAGER)
    @Primary
    @ConditionalOnMissingBean(name = DEFAULT_LOCK_MANAGER)
    public ILockManager localLockManager() {
        return new LocalLockManager(DEFAULT_LOCK_MANAGER);
    }
}
